<?php
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
/**
 * Class::BigDaddy
 * Main Class for BigDaddy and is inherited by all subsequent BigDaddy classes
 * @author Duleepa Wijayawardhana <dups@bioware.com>
 * @version 30/05/2006 11:30:24
 *
 */
class BigDaddy
{
    protected $Role;
    protected $Audit;
    
    /**
     * COnstructor
     */
    public function __construct()
    {
        $this->Role = $GLOBALS["Role"];
        $this->Audit = $GLOBALS["Audit"];
    }
    /**
     * IsUserAllowed
     * @author Duleepa Wijayawardhana <dups@bioware.com>
     * @version Fri Oct 27 10:36:26 2006
     * @param string $sMethod
     *
     * Method level access
     */
    public function IsUserAllowed($sMethod)
    {
        
        
        preg_match("/(.*?)::(.*)/", $sMethod, $aMatches);
        
        switch ($aMatches[1])
        {
            case "BigDaddyControl":
                    
                switch($aMatches[2])
                {
                    case "RemoveCron":
                        $sRoleAction = "cron-remove";
                        break;
                    case "RemoveCronCategory":
                    case "SetCronCategory":
                    
                        $sRoleAction = "cron-meta";
                        break;
                    case "SetCronDelayed":
                    case "SetCronDelayedByCategory":
                        $sRoleAction = "cron-delay";
                        break;
                    case "SetCronDisabled":
                    case "SetCronDisabledByCategory":
                        $sRoleAction = "cron-disable";
                        break;
                    case "SetCronEnabled":
                    case "SetCronEnabledByCategory":
                        $sRoleAction = "cron-enable";
                        break;
                    case "SetCronGlobalMonitoringStatusDisabled":
                    case "SetCronGlobalStatusDelayed":
                    case "SetCronGlobalStatusDisabled":
                    case "SetCronGlobalStatusNormal":
                        $sRoleAction = "cron-global";
                        break;
                    case "SetCron":
                    case "SetCronLastRunToEmpty":
                    case "RemoveCronFromCategoryMap":
                    case "SetCronCategoryMap":
                        $sRoleAction = "cron-edit";
                        break;
                    case "SetCronMonitoringDisabled":
                    case "SetCronMonitoringDisabledByCategory":
                        $sRoleAction = "cron-mon-disable";
                        break;
                    case "SetCronMonitoringEnabled":
                    case "SetCronMonitoringEnabledByCategory":
                        $sRoleAction = "cron-mon-enable";
                        break;
                    case "RemoveServer":
                    case "RemoveServerGroup":
                    case "RemoveServerMod":
                    case "RemoveServerModulesByServer":
                        $sRoleAction = "server-remove";
                        break;
                    case "RemoveServerCategory":
                    case "SetServerCategory":
                        $sRoleAction = "server-meta";
                        break;
                    case "SetServer":
                    case "SetServerCategoryMap":
                    case "SetServerGroup":
                    case "SetServerGroupModule":
                    case "RemoveServerGroupModule":
                    case "RemoveServerGroupModuleByModuleID":
                    case "RemoveServerGroupModuleByServerID":
                    case "RemoveFromServerCategoryMap":
                    case "SetServerMod":
                    case "SetServerModCopy":
                    case "SetServerModCopyAll":
                        $sRoleAction = "server-edit";
                        break;
                    case "SetGlobalServerStatusDelayed":
                    case "SetGlobalServerStatusDisabled":
                    case "SetGlobalServerStatusNormal":
                        $sRoleAction = "server-global";
                        break;
                    case "SetServerGroupDelay":
                    case "SetServerModStatusDelayed":
                    case "SetServerStatusDelayed":
                    case "SetServerStatusDelayedByCategory":
                        $sRoleAction = "server-delay";
                        break;
                    case "SetServerGroupStatusToDisabled":
                    case "SetServerModStatusDisabled":
                    case "SetServerStatusDisabled":
                    case "SetServerStatusDisabledByCategory":
                        $sRoleAction = "server-disable";
                        break;
                    case "SetServerGroupStatusToEnabled":
                    case "SetServerModStatusEnabled":
                    case "SetServerStatusEnabled":
                    case "SetServerStatusEnabledByCategory":
                        $sRoleAction = "server-enable";
                        break;
                    case "RemoveIniFile":
                    case "RemoveModule":
                    case "SetIniFile":
                    case "SetModule":
                    case "SetPhoneTag":
                    case "RemovePhoneTag":
                        $sRoleAction = "meta-admin";
                        break;
                    case "SetIncident":
                    case "SetIncidentComment":
                        $sRoleAction = "incident-edit";
                        break;
                    case "RemoveIncident":
                    case "RemoveIncidentComment":
                        $sRoleAction = "incident-admin";
                        break;
                }
                break;
            
        }
        
        //echo $sMethod." ".$sRoleAction." ".$aMatches[1]." ".$aMatches[2];
        //var_dump($aMatches);
        //exit;
        
        if ($this->Role->IsGlobalActionAvailableToUser($sRoleAction))
        {
            return true;
        }
        
        return false;
    }
    /**
     * IsUserAllowedByAction
     * Check an action against a user
     * @author Duleepa Wijayawardhana <dups@bioware.com>
     * @version Sun Oct 29 17:17:59 2006
     */
    public function IsUserAllowedByAction($sAction)
    {
        if ($this->Role->IsGlobalActionAvailableToUser($sAction))
        {
            return true;
        }
        return false;
    }
    
}

?>
